package com.youku.plugins.endcardV4New.model.data
{
   import flash.events.EventDispatcher;
   import flash.display.Loader;
   import flash.utils.Timer;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import flash.events.TimerEvent;
   import flash.net.URLRequest;
   import flash.system.LoaderContext;
   import com.youku.plugins.endcardV4New.EndCardEvent;
   import flash.display.Bitmap;
   import flash.display.BitmapData;
   
   public class LoadImageList extends EventDispatcher
   {
      
      public function LoadImageList(param1:PrivateClass) {
         super();
         this.init();
      }
      
      private static var _instance:LoadImageList;
      
      public static function getInstance() : LoadImageList {
         if(_instance == null)
         {
            _instance = new LoadImageList(new PrivateClass());
         }
         return _instance as LoadImageList;
      }
      
      private var _loader:Loader;
      
      private var _array:Array;
      
      private var _timer:Timer;
      
      private function init() : void {
         this._loader = new Loader();
         this._array = new Array();
         this._timer = new Timer(5 * 1000);
         this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onComplete);
         this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onError);
         this._loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onError);
         this._timer.addEventListener(TimerEvent.TIMER,this.onError);
      }
      
      public function addtoList(param1:String, param2:String, param3:String = null) : void {
         this._array.push(
            {
               "url":param1,
               "type":param2,
               "subType":param3
            });
      }
      
      public function load() : void {
         if(!this._array.length)
         {
            return;
         }
         if(this._timer.running)
         {
            return;
         }
         this._loader.load(new URLRequest(this._array[0].url),new LoaderContext(true));
         this._timer.reset();
         this._timer.start();
      }
      
      public function close() : void {
         try
         {
            this._loader.close();
         }
         catch(e:Error)
         {
         }
         this._array = new Array();
         this._timer.stop();
      }
      
      private function onComplete(param1:Event) : void {
         this.dispatchImg(true);
      }
      
      private function onError(param1:Event) : void {
         this.dispatchImg(false);
      }
      
      private function dispatchImg(param1:Boolean) : void {
         var _loc2_:EndCardEvent = null;
         if(this._array.length == 0)
         {
            return;
         }
         if(param1)
         {
            _loc2_ = new EndCardEvent(EndCardEvent.RELATIVE_IMAGE_LOAD_COMPLETE,
               {
                  "img":this._loader.content,
                  "type":this._array[0].type,
                  "subType":this._array[0].subType
               });
         }
         else
         {
            _loc2_ = new EndCardEvent(EndCardEvent.RELATIVE_IMAGE_LOAD_COMPLETE,
               {
                  "img":this.errorImage,
                  "type":this._array[0].type,
                  "subType":this._array[0].subType
               });
         }
         this.dispatchEvent(_loc2_);
         this._timer.stop();
         this._array.shift();
         this.load();
      }
      
      private function get errorImage() : Bitmap {
         var _loc1_:BitmapData = new BitmapData(100,100,false,3355443);
         var _loc2_:Bitmap = new Bitmap(_loc1_);
         return _loc2_;
      }
   }
}
class PrivateClass extends Object
{
   
   function PrivateClass() {
      super();
   }
}
